package com.link510.aitools.core.enums;

import com.google.common.base.Strings;

import java.util.Arrays;
import java.util.Objects;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 命令
 */
@AllArgsConstructor
@Getter
public enum MessageAction {

    Register("register", "设备注册"),
    Heart("heart", "心跳数据上报"),
    CallBack("callback", "消息回调"),
    HeartCallBack("callback", "消息回调"),
    Event("event", "事件命令"),
    Setting("setting", "远程设置");

    /**
     * 命令
     */
    private final String action;

    /**
     * 参数名称
     */
    private final String name;

    /**
     * 获取实体
     *
     * @param action 命令
     * @return Command
     */
    public static MessageAction getAction(String action) {

        try {

            if (Strings.isNullOrEmpty(action)) {
                return Heart;
            }

            for (MessageAction action2 : values()) {
                if (action2 == null) {
                    continue;
                }

                if (action2.getAction().equals(action)) {
                    return action2;
                }

            }

        } catch (Exception ignored) {

        }
        return MessageAction.Heart;
    }

}
